<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div index="1" id="demo" class="nav">

    </div>
    <script>
        var div=document.querySelector('div');
        //1.获取元素的属性值
        //(1)element.属性
        console.log(div.id);
        //(2)element.getAttribute("属性") get得到  Attribute属性的意思
        //我们自己添加的属性 叫做自定义属性
        console.log(div.getAttribute('id'));
        console.log(div.getAttribute('index'));
        //2.设置属性值
        //(1).element.属性='值';
        div.id='test';
        div.className="navs";
        //(2)element.setAttribute("属性","值");主要针对自定义属性
        div.setAttribute("index",2);
        div.setAttribute("class","footer");
        //3.移除属性 removeAttribute(属性)
        div.removeAttribute("index");

    </script>
</body>
</html>